<div class="widget transparent nopadding no-margin">
    <div class="widget-header">
        <span class="widget-caption">筛选</span>
        <div class="widget-buttons">
            <a href="#" data-toggle="collapse">
                <i class="fa fa-minus blue "></i>
            </a>
        </div>
    </div>
    <div class="widget-body no-padding-bottom">
        <form class="form" id="${searchFormId}" role="form" action="${actionUrl}">
            <input type="hidden" name="containerId" value="${containerId}">
            <input type="hidden" name="searchFormId" value="${searchFormId}">
            <input type="hidden" name="handlePermissionId" value="${handlePermissionId}">
            <div class="row">
                <div class="col-sm-9">
                    <div class="form-group">
                        <label class="sr-only" for="name">名称</label>
                        <input type="text" class="form-control" name="name" placeholder="名称" value="${search_map.name[0]}">
                    </div>
                </div>
                <div class="col-sm-2">
                    <button type="button" class="btn btn-info shiny search" id="addHandlePermissionClass_search" onclick="loadHandlePermissionClassList('${containerId}','${searchFormId}','${handlePermissionId}')"><i class="fa fa-search"></i>搜索</button>
                </div>
            </div>
        </form>
    </div>
</div>
<div class="topPagingBar">
    ${pagingBar}
</div>
<div class="table-scrollable">
    <!-- 数据表列信息列表 -->
    <table class="table table-bordered dataTable fixedTable">
        <thead>
        <tr>
            <th class="fixedColumn" style="width: 100px">操作</th>
            <th title="属性名">序号</th>
            <th title="权限名称">操作权限名称</th>
            <th title="权限名称">类属性名</th>
            <th title="权重">权重</th>
            <th title="是否禁用">是否禁用</th>
            <th title="创建时间">创建时间</th>
        </tr>
        </thead>
        <tbody>
        <#if page_bean.list?size==0>
            <tr>
                <td align="center" colspan="8">无数据</td>
            </tr>
        </#if>
        <#list page_bean.list as data>
            <tr>
                <td align="center">
                    <a class="btn btn-default btn-xs icon-only green" href="javascript:void(0);" onclick=editHandlePermissClass('${data.id}','${data.name???string(data.name?html,"")}','${data.weight}','${data.isForbidden?string('true','false')}')><i class="fa  fa-edit"></i></a>
                    <a class="btn btn-default btn-xs icon-only red delete" href="javascript:void(0);" targetCallbackClickTagId="reloadHandlePermissionDetails" deleteUrl="${deleteUrl}" targetDataId="${data.id}"><i class="fa fa-trash-o"></i></a>
                </td>
                <td>${data_index+1+(page_bean.pageNo-1)*page_bean.pageSize}</td>
                <td>${(data.handlePermission.name???string(data.handlePermission.name?html,""))!'未设置'}</td>
                <td>${(data.name???string(data.name?html,""))!'未设置'}</td>
                <td>${(data.weight???string(data.weight?html,""))!'未设置'}</td>
                <td>${data.isForbidden?string("是","否")}</td>
                <td>${(data.createTime???string(data.createTime?html,""))!'未设置'}</td>
            </tr>
        </#list>
        </tbody>
    </table>
</div>
${pagingBar}
<!-- 新增操作权限class begin -->
<div class="col-lg-12 col-sm-12 col-xs-12" id="editHandlePermissClass" style="display:none;">
    <div id="horizontal-form">
        <form class="form-horizontal bv-form" role="form"
              action="${saveUrl}" method="post" responseType="JSON" role="form" id="editForm_${searchFormId}"
              data-bv-message="This value is not valid"
              data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
              data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
              data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">
            <input type="hidden" name="formKey" value="${formKey}">
            <input type="hidden" name="formToken" value="${formToken}">
            <input type="hidden" name="id">
            <input type="hidden" name="handlePermissionId" value="${handlePermissionId}">
            <div class="form-group">
                <label for="name" class="col-sm-2 control-label no-padding-right">名称</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" name="name" data-bv-message="This value is not valid" required="required" placeholder="名称">
                </div>
            </div>
            <div class="form-group">
                <label for="weight" class="col-sm-2 control-label">权重</label>
                <div class="col-sm-10">
                    <input type="text" class="spinner-input form-control" min="1" maxlength="3" name="weight" placeholder="权重" required="required"  data-bv-numeric="true" data-bv-numeric-message="请输入数字">
                </div>
            </div>
            <div class="form-group">
                <label for="isForbidden" class="col-sm-2 control-label no-padding-right">是否禁用</label>
                <div class="col-xs-10">
                    <input type="hidden" name="isForbidden" value="true">
                    <label>
                        <input class="checkbox-slider yesno" data-target-input-name="isForbidden" id="isForbidden" type="checkbox" checked="checked">
                        <span class="text"></span>
                    </label>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="assets/js/fuelux/spinner/fuelux.spinner.min.js"></script>
<!--新增操作权限class end-->
<script type="text/javascript">
    function editHandlePermissClass(id, name, weight, isForbidden) {
        var data = {
            id: id,
            name: name,
            weight: weight,
            isForbidden: isForbidden ? isForbidden : ""
        }
        addHandlePermissClass(data);
    }
    function addHandlePermissClass(data) {
        var editFormId = "editHandlePermissClass";
        if ($("#" + editFormId).size() == 0) {
            alert("请在选择已勾选的菜单权限,再选择需要设置的操作权限!");
            return;
        }
        var clone = $("#" + editFormId).clone();
        var submitButtonsId = new Date().getTime() + "editFormSubmitBtn_${searchFormId}";
        var newId = new Date().getTime() + "editForm_${searchFormId}";
        var message = clone.find("form").attr("id", newId).attr("data-bv-submitButtons", submitButtonsId);
        var editDialog = bootbox.dialog({
            message: message,
            title: "新增操作权限class属性",
            buttons: {
                "保存": {
                    className: "btn-blue",
                    callback: function () {
                       form.data("bootstrapValidator").validate();//手动验证并提交
                    }
                }
            },
            onEscape: function () {
                setTimeout(function () {
                    reloadHandlePermissionDetails();
                }, 300)
            }
        });
        //初始化表单验证
        var form = inintValidatorForm($("#" + newId));
        //初始化编辑时的默认值
        data = data || {};
        console.log("data: " + data);
        console.log(data);
        $.each(data, function (key, value) {
            if (key == "isForbidden") {
                message.find("#isForbidden").get(0).checked = (value && value == "true") ? true : false;
            } else {
                message.find("[name='" + key + "']").val(value);
            }
        });
        //数字输入
        $(".spinner_weight").spinner({
            min: 1,
            value: data.weight ? data.weight : 1
        });
        //表单回调
        $(document).on("ajaxSubmitCallback", "#" + newId, function (event, data) {
            if (data.resCode == 200) {
                resetValidatorForm(this);
                setTimeout(function () {
                    reloadHandlePermissionDetails();
                    //更新token信息
                    $("#"+newId+" [name='formKey']").val(Math.randomStr());
                    $("#"+newId+" [name='formToken']").val(Math.randomStr());
                }, 300)
            } else {
                ajaxError(data.resMsg);
            }
        });
    }
</script>